package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.mapper.TbParkingLotMapper;
import com.bwie.pojo.TbParking;
import com.bwie.pojo.TbParkingLot;
import com.bwie.service.TbParkingLotService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class TbParkingLotServiceImpl implements TbParkingLotService {
    @Resource
    TbParkingLotMapper tbParkingLotMapper;
    @Override
    public R getParkingLotList(PageInfoVo pageInfoVo) {

        Page<TbParkingLot> page = new Page<>(pageInfoVo.getPageNum(), pageInfoVo.getPageSize());
        Page<TbParkingLot> tbParkingLotPage = tbParkingLotMapper.selectPageList(page, pageInfoVo.getKeyWord());
        return R.OK(tbParkingLotPage);
    }

    @Override
    public R addCar(TbParkingLot tbParkingLot) {
        TbParkingLot tbParkingLot1 = new TbParkingLot();
        tbParkingLot1.setNumber(tbParkingLot.getNumber());
        tbParkingLot1.setParkingId(1);
        tbParkingLot1.setAdmissionTime(new Date());
        tbParkingLot1.setBilling("5/小时");
        tbParkingLot1.setDuration("3小时");
        tbParkingLot1.setPrice(15.00);
        tbParkingLot1.setStatus(0);

        tbParkingLotMapper.insert(tbParkingLot1);
        return R.OK();
    }

    @Override
    public R updateCarStatus(TbParkingLot tbParkingLot) {
        TbParkingLot tbParkingLot1 = new TbParkingLot();
        tbParkingLot1.setId(tbParkingLot.getId());
        tbParkingLot1.setNumber(tbParkingLot.getNumber());

        tbParkingLot1.setStatus(1);
        tbParkingLotMapper.updateById(tbParkingLot1);
        return R.OK();
    }

    @Override
    public R deleteCar(TbParkingLot tbParkingLot) {
        tbParkingLotMapper.deleteById(tbParkingLot);
        return R.OK();
    }
}
